<?php
/**
 * Users controller class
 *
 */
class AjaxController extends Admin_Controller
{

	public function init()
    {
    	parent::init();

    }

    public function cropObjectAction()
    {
        $id = $this->_getParam('id');
    	if(!($id > 0)) die('ERROR');

        $d = $this->table_objects->GetDataRow($id);

        $sizes = Zend_Registry::get('config')->images->modules->objects->list->toArray();

        $output = '<input value="0" type="hidden" rel="x"/>';
        $output .= '<input value="0" type="hidden" rel="y"/>';
        $output .= '<input value="0" type="hidden" rel="w"/>';
        $output .= '<input value="0" type="hidden" rel="h"/>';

        $output .= '<table><tr><td>';
        $output .= '<img src="'.$this->_http_files.$d['path'].$id.'original'.$d['file_name'].'" class="cropbox" />';
        $output .= '</td><td>';
        $output .= '<div style="width:'.$sizes['width'].'px;height:'.$sizes['height'].'px;overflow:hidden;" class="preview">';
        $output .= '<img src="'.$this->_http_files.$d['path'].$id.'original'.$d['file_name'].'" class="preview"/>';
        $output .= '</div></td></tr></table>';
        $output .= '<div class="go">';
        $output .= '<input type="button" class="submit" value="Вырезать" onclick="cropSelectedPhoto('.$id.')"/>';
        $output .= '<input type="button" class="submit" value="Отмена" onclick="window.location.reload( true );"/>';
        $output .= '</div>';

        echo $output;
        die();
    }

    // used for photo objects
    public function cropSelectedAction()
    {
        $id = $this->_request->getParam('id');
    	if(!($id > 0)) die();

        $coords['x'] = $this->_getParam('x', 0);
        $coords['y'] = $this->_getParam('y', 0);
        $coords['w'] = $this->_getParam('w', 0);
        $coords['h'] = $this->_getParam('h', 0);

        $d = $this->table_objects->GetDataRow($id);

        $this->CropImage($id, $d['path'], $d['file_name'], $coords, 'objects', 'list', false);

        die('OK');
    }




}
